package com.example.serviceB.dao;

import com.example.serviceB.req.TransferInReq;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface AccountMapper {

    @Update("update account " +
            "   set frozen_amount = frozen_amount + #{req.amount} " +
            " where id = #{req.accountId} ")
    void transferIn(@Param("req") TransferInReq req);

    @Update("update account " +
            "   set amount = amount + #{req.amount}," +
            "       frozen_amount = frozen_amount - #{req.amount} " +
            " where id = #{req.accountId} ")
    void confirmTransferIn(@Param("req") TransferInReq req);

    @Update("update account " +
            "   set frozen_amount = frozen_amount - #{req.amount} " +
            " where id = #{req.accountId} ")
    void cancelTransferIn(@Param("req") TransferInReq req);

}
